package com.shwread.android.ui.dialog;

import android.app.ActionBar.LayoutParams;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.shwread.android.qysw10000182.R;

public class BookTicketActivateDialog
        extends
        Dialog
        implements
        android.view.View.OnClickListener
{
	private Context context;
	private Button   btnEnsure;
	private TextView tvContent;
	private String   content;
	private boolean  isSuccess;
	private SimpleListener listener;
	
	/**
	 * 
	 * @param context
	 * @param isSuccess true:激活成功，false:激活失败
	 * @param content 
	 * @param listener
	 */
	public BookTicketActivateDialog(Context context,boolean  isSuccess, String content,SimpleListener listener) {
		super(context, R.style.common_dialog);
		this.context = context;
		this.content = content;
		this.isSuccess = isSuccess;
		this.listener = listener;
		
	}
    @Override
	protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setCancelable(false);
	    getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
	    getWindow().setGravity(Gravity.CENTER_VERTICAL);
		findViews();
	}
	
	private void findViews() {
		View view = null;
		if(isSuccess){ //激活成功
			view = LayoutInflater.from(context).inflate(R.layout.book_ticket_activate_success_dialog, null);
			btnEnsure = (Button) view.findViewById(R.id.book_ticket_activate_success_dialog_btn);
			tvContent = (TextView) view.findViewById(R.id.book_ticket_activate_success_dialog_tv);
		}else{ //激活失败
			view = LayoutInflater.from(context).inflate(R.layout.book_ticket_activate_fail_dialog, null);
			btnEnsure = (Button) view.findViewById(R.id.book_ticket_activate_dialog_btn);
			tvContent = (TextView) view.findViewById(R.id.book_ticket_activate_dialog_tv);
		}
		tvContent.setText(content);
		btnEnsure.setOnClickListener(this);
		setContentView(view);
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.book_ticket_activate_success_dialog_btn:
			case R.id.book_ticket_activate_dialog_btn:
				if(listener!=null) listener.ok();
				dismiss();
				break;
		}
	}
	
}
